/*
 * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

#ifndef BOARD_H
#define BOARD_H

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

//
// Included Files
//

#include "driverlib.h"
#include "device.h"

//*****************************************************************************
//
// PinMux Configurations
//
//*****************************************************************************

//
// EPWM1 -> myEPWM0 Pinmux
//
//
// EPWM1A - GPIO Settings
//
#define GPIO_PIN_EPWM1A 0
#define myEPWM0_EPWMA_GPIO 0
#define myEPWM0_EPWMA_PIN_CONFIG GPIO_0_EPWM1A
//
// EPWM1B - GPIO Settings
//
#define GPIO_PIN_EPWM1B 1
#define myEPWM0_EPWMB_GPIO 1
#define myEPWM0_EPWMB_PIN_CONFIG GPIO_1_EPWM1B

//
// EPWM2 -> myEPWM1 Pinmux
//
//
// EPWM2A - GPIO Settings
//
#define GPIO_PIN_EPWM2A 2
#define myEPWM1_EPWMA_GPIO 2
#define myEPWM1_EPWMA_PIN_CONFIG GPIO_2_EPWM2A
//
// EPWM2B - GPIO Settings
//
#define GPIO_PIN_EPWM2B 3
#define myEPWM1_EPWMB_GPIO 3
#define myEPWM1_EPWMB_PIN_CONFIG GPIO_3_EPWM2B

//
// EPWM3 -> myEPWM2 Pinmux
//
//
// EPWM3A - GPIO Settings
//
#define GPIO_PIN_EPWM3A 4
#define myEPWM2_EPWMA_GPIO 4
#define myEPWM2_EPWMA_PIN_CONFIG GPIO_4_EPWM3A
//
// EPWM3B - GPIO Settings
//
#define GPIO_PIN_EPWM3B 5
#define myEPWM2_EPWMB_GPIO 5
#define myEPWM2_EPWMB_PIN_CONFIG GPIO_5_EPWM3B
//
// GPIO15 - GPIO Settings
//
#define KEY1_GPIO_PIN_CONFIG GPIO_15_GPIO15
//
// GPIO26 - GPIO Settings
//
#define KEY2_GPIO_PIN_CONFIG GPIO_26_GPIO26
//
// GPIO27 - GPIO Settings
//
#define KEY3_GPIO_PIN_CONFIG GPIO_27_GPIO27
//
// GPIO25 - GPIO Settings
//
#define KEY4_GPIO_PIN_CONFIG GPIO_25_GPIO25
//
// GPIO124 - GPIO Settings
//
#define EN_GATE_GPIO_PIN_CONFIG GPIO_124_GPIO124
//
// GPIO131 - GPIO Settings
//
#define Test_Pin_GPIO_PIN_CONFIG GPIO_131_GPIO131
//
// GPIO61 - GPIO Settings
//
#define SPI_CS_GPIO_PIN_CONFIG GPIO_61_GPIO61

//
// SCIA -> mySCI0 Pinmux
//
//
// SCIRXDA - GPIO Settings
//
#define GPIO_PIN_SCIRXDA 43
#define mySCI0_SCIRX_GPIO 43
#define mySCI0_SCIRX_PIN_CONFIG GPIO_43_SCIRXDA
//
// SCITXDA - GPIO Settings
//
#define GPIO_PIN_SCITXDA 42
#define mySCI0_SCITX_GPIO 42
#define mySCI0_SCITX_PIN_CONFIG GPIO_42_SCITXDA

//
// SCIB -> mySCI1 Pinmux
//
//
// SCIRXDB - GPIO Settings
//
#define GPIO_PIN_SCIRXDB 19
#define mySCI1_SCIRX_GPIO 19
#define mySCI1_SCIRX_PIN_CONFIG GPIO_19_SCIRXDB
//
// SCITXDB - GPIO Settings
//
#define GPIO_PIN_SCITXDB 18
#define mySCI1_SCITX_GPIO 18
#define mySCI1_SCITX_PIN_CONFIG GPIO_18_SCITXDB

//*****************************************************************************
//
// ADC Configurations
//
//*****************************************************************************
#define myADC0_BASE ADCA_BASE
#define myADC0_RESULT_BASE ADCARESULT_BASE
#define myADC0_SOC0_A2_IC ADC_SOC_NUMBER0
#define myADC0_FORCE_SOC0_A2_IC ADC_FORCE_SOC0
#define myADC0_SAMPLE_WINDOW_SOC0_A2_IC 75
#define myADC0_TRIGGER_SOURCE_SOC0_A2_IC ADC_TRIGGER_EPWM3_SOCA
#define myADC0_CHANNEL_SOC0_A2_IC ADC_CH_ADCIN2
#define myADC0_SOC1_A3_PVDD ADC_SOC_NUMBER1
#define myADC0_FORCE_SOC1_A3_PVDD ADC_FORCE_SOC1
#define myADC0_SAMPLE_WINDOW_SOC1_A3_PVDD 75
#define myADC0_TRIGGER_SOURCE_SOC1_A3_PVDD ADC_TRIGGER_EPWM3_SOCA
#define myADC0_CHANNEL_SOC1_A3_PVDD ADC_CH_ADCIN3
#define myADC0_PPB1 ADC_PPB_NUMBER1
#define myADC0_SOC_PPB1 ADC_SOC_NUMBER0
void myADC0_init();

#define myADC1_BASE ADCB_BASE
#define myADC1_RESULT_BASE ADCBRESULT_BASE
#define myADC1_SOC0_B2_IB ADC_SOC_NUMBER0
#define myADC1_FORCE_SOC0_B2_IB ADC_FORCE_SOC0
#define myADC1_SAMPLE_WINDOW_SOC0_B2_IB 75
#define myADC1_TRIGGER_SOURCE_SOC0_B2_IB ADC_TRIGGER_EPWM3_SOCA
#define myADC1_CHANNEL_SOC0_B2_IB ADC_CH_ADCIN2
#define myADC1_SOC1_B3_VC ADC_SOC_NUMBER1
#define myADC1_FORCE_SOC1_B3_VC ADC_FORCE_SOC1
#define myADC1_SAMPLE_WINDOW_SOC1_B3_VC 75
#define myADC1_TRIGGER_SOURCE_SOC1_B3_VC ADC_TRIGGER_EPWM3_SOCA
#define myADC1_CHANNEL_SOC1_B3_VC ADC_CH_ADCIN3
#define myADC1_PPB1 ADC_PPB_NUMBER1
#define myADC1_SOC_PPB1 ADC_SOC_NUMBER0
void myADC1_init();

#define myADC2_BASE ADCC_BASE
#define myADC2_RESULT_BASE ADCCRESULT_BASE
#define myADC2_SOC0_C2_IA ADC_SOC_NUMBER0
#define myADC2_FORCE_SOC0_C2_IA ADC_FORCE_SOC0
#define myADC2_SAMPLE_WINDOW_SOC0_C2_IA 75
#define myADC2_TRIGGER_SOURCE_SOC0_C2_IA ADC_TRIGGER_EPWM3_SOCA
#define myADC2_CHANNEL_SOC0_C2_IA ADC_CH_ADCIN2
#define myADC2_SOC1_C3_VB ADC_SOC_NUMBER1
#define myADC2_FORCE_SOC1_C3_VB ADC_FORCE_SOC1
#define myADC2_SAMPLE_WINDOW_SOC1_C3_VB 75
#define myADC2_TRIGGER_SOURCE_SOC1_C3_VB ADC_TRIGGER_EPWM3_SOCA
#define myADC2_CHANNEL_SOC1_C3_VB ADC_CH_ADCIN3
#define myADC2_SOC2_IN14_VA ADC_SOC_NUMBER2
#define myADC2_FORCE_SOC2_IN14_VA ADC_FORCE_SOC2
#define myADC2_SAMPLE_WINDOW_SOC2_IN14_VA 75
#define myADC2_TRIGGER_SOURCE_SOC2_IN14_VA ADC_TRIGGER_EPWM3_SOCA
#define myADC2_CHANNEL_SOC2_IN14_VA ADC_CH_ADCIN14
#define myADC2_PPB1 ADC_PPB_NUMBER1
#define myADC2_SOC_PPB1 ADC_SOC_NUMBER0
void myADC2_init();


//*****************************************************************************
//
// CPUTIMER Configurations
//
//*****************************************************************************
#define myCPUTIMER0_BASE CPUTIMER0_BASE
void myCPUTIMER0_init();

//*****************************************************************************
//
// DAC Configurations
//
//*****************************************************************************
#define myDAC0_BASE DACA_BASE
void myDAC0_init();
#define myDAC1_BASE DACB_BASE
void myDAC1_init();

//*****************************************************************************
//
// EPWM Configurations
//
//*****************************************************************************
#define myEPWM0_BASE EPWM1_BASE
#define myEPWM0_TBPRD 5000
#define myEPWM0_COUNTER_MODE EPWM_COUNTER_MODE_UP_DOWN
#define myEPWM0_TBPHS 0
#define myEPWM0_CMPA 0
#define myEPWM0_CMPB 3000
#define myEPWM0_CMPC 0
#define myEPWM0_CMPD 0
#define myEPWM0_DBRED 100
#define myEPWM0_DBFED 100
#define myEPWM0_TZA_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM0_TZB_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM0_INTERRUPT_SOURCE EPWM_INT_TBCTR_DISABLED
#define myEPWM1_BASE EPWM2_BASE
#define myEPWM1_TBPRD 5000
#define myEPWM1_COUNTER_MODE EPWM_COUNTER_MODE_UP_DOWN
#define myEPWM1_TBPHS 0
#define myEPWM1_CMPA 0
#define myEPWM1_CMPB 3000
#define myEPWM1_CMPC 0
#define myEPWM1_CMPD 0
#define myEPWM1_DBRED 100
#define myEPWM1_DBFED 100
#define myEPWM1_TZA_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM1_TZB_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM1_INTERRUPT_SOURCE EPWM_INT_TBCTR_DISABLED
#define myEPWM2_BASE EPWM3_BASE
#define myEPWM2_TBPRD 5000
#define myEPWM2_COUNTER_MODE EPWM_COUNTER_MODE_UP_DOWN
#define myEPWM2_TBPHS 0
#define myEPWM2_CMPA 0
#define myEPWM2_CMPB 3000
#define myEPWM2_CMPC 0
#define myEPWM2_CMPD 0
#define myEPWM2_DBRED 100
#define myEPWM2_DBFED 100
#define myEPWM2_TZA_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM2_TZB_ACTION EPWM_TZ_ACTION_HIGH_Z
#define myEPWM2_INTERRUPT_SOURCE EPWM_INT_TBCTR_DISABLED

//*****************************************************************************
//
// GPIO Configurations
//
//*****************************************************************************
#define KEY1 15
void KEY1_init();
#define KEY2 26
void KEY2_init();
#define KEY3 27
void KEY3_init();
#define KEY4 25
void KEY4_init();
#define EN_GATE 124
void EN_GATE_init();
#define Test_Pin 131
void Test_Pin_init();
#define SPI_CS 61
void SPI_CS_init();

//*****************************************************************************
//
// INPUTXBAR Configurations
//
//*****************************************************************************
#define myINPUTXBARINPUT0_SOURCE 15
#define myINPUTXBARINPUT0_INPUT XBAR_INPUT4
void myINPUTXBARINPUT0_init();
#define myINPUTXBARINPUT1_SOURCE 26
#define myINPUTXBARINPUT1_INPUT XBAR_INPUT5
void myINPUTXBARINPUT1_init();
#define myINPUTXBARINPUT2_SOURCE 27
#define myINPUTXBARINPUT2_INPUT XBAR_INPUT6
void myINPUTXBARINPUT2_init();
#define myINPUTXBARINPUT3_SOURCE 25
#define myINPUTXBARINPUT3_INPUT XBAR_INPUT13
void myINPUTXBARINPUT3_init();

//*****************************************************************************
//
// INTERRUPT Configurations
//
//*****************************************************************************

// Interrupt Settings for INT_myADC0_1
#define INT_myADC0_1 INT_ADCA1
#define INT_myADC0_1_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP1
extern __interrupt void INT_myADC0_1_ISR(void);

// Interrupt Settings for INT_myCPUTIMER0
#define INT_myCPUTIMER0 INT_TIMER0
#define INT_myCPUTIMER0_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP1
extern __interrupt void INT_myCPUTIMER0_ISR(void);

// Interrupt Settings for INT_KEY1_XINT
#define INT_KEY1_XINT INT_XINT1
#define INT_KEY1_XINT_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP1
extern __interrupt void INT_KEY1_XINT_ISR(void);

// Interrupt Settings for INT_KEY2_XINT
#define INT_KEY2_XINT INT_XINT2
#define INT_KEY2_XINT_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP1
extern __interrupt void INT_KEY2_XINT_ISR(void);

// Interrupt Settings for INT_KEY3_XINT
#define INT_KEY3_XINT INT_XINT3
#define INT_KEY3_XINT_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP12
extern __interrupt void INT_KEY3_XINT_ISR(void);

// Interrupt Settings for INT_KEY4_XINT
#define INT_KEY4_XINT INT_XINT4
#define INT_KEY4_XINT_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP12
extern __interrupt void INT_KEY4_XINT_ISR(void);

// Interrupt Settings for INT_mySCI0_RX
#define INT_mySCI0_RX INT_SCIA_RX
#define INT_mySCI0_RX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCI0_RX_ISR(void);

// Interrupt Settings for INT_mySCI0_TX
#define INT_mySCI0_TX INT_SCIA_TX
#define INT_mySCI0_TX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCI0_TX_ISR(void);

// Interrupt Settings for INT_mySCI1_RX
#define INT_mySCI1_RX INT_SCIB_RX
#define INT_mySCI1_RX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCI1_RX_ISR(void);

// Interrupt Settings for INT_mySCI1_TX
#define INT_mySCI1_TX INT_SCIB_TX
#define INT_mySCI1_TX_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP9
extern __interrupt void INT_mySCI1_TX_ISR(void);

//*****************************************************************************
//
// SCI Configurations
//
//*****************************************************************************
#define mySCI0_BASE SCIA_BASE
#define mySCI0_BAUDRATE 3000000
#define mySCI0_CONFIG_WLEN SCI_CONFIG_WLEN_8
#define mySCI0_CONFIG_STOP SCI_CONFIG_STOP_ONE
#define mySCI0_CONFIG_PAR SCI_CONFIG_PAR_NONE
#define mySCI0_FIFO_TX_LVL SCI_FIFO_TX8
#define mySCI0_FIFO_RX_LVL SCI_FIFO_RX1
void mySCI0_init();
#define mySCI1_BASE SCIB_BASE
#define mySCI1_BAUDRATE 2500000
#define mySCI1_CONFIG_WLEN SCI_CONFIG_WLEN_8
#define mySCI1_CONFIG_STOP SCI_CONFIG_STOP_ONE
#define mySCI1_CONFIG_PAR SCI_CONFIG_PAR_NONE
#define mySCI1_FIFO_TX_LVL SCI_FIFO_TX8
#define mySCI1_FIFO_RX_LVL SCI_FIFO_RX11
void mySCI1_init();

//*****************************************************************************
//
// SYNC Scheme Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// XINT Configurations
//
//*****************************************************************************
#define KEY1_XINT GPIO_INT_XINT1
#define KEY1_XINT_TYPE GPIO_INT_TYPE_RISING_EDGE
void KEY1_XINT_init();
#define KEY2_XINT GPIO_INT_XINT2
#define KEY2_XINT_TYPE GPIO_INT_TYPE_RISING_EDGE
void KEY2_XINT_init();
#define KEY3_XINT GPIO_INT_XINT3
#define KEY3_XINT_TYPE GPIO_INT_TYPE_RISING_EDGE
void KEY3_XINT_init();
#define KEY4_XINT GPIO_INT_XINT4
#define KEY4_XINT_TYPE GPIO_INT_TYPE_RISING_EDGE
void KEY4_XINT_init();

//*****************************************************************************
//
// Board Configurations
//
//*****************************************************************************
void	Board_init();
void	ADC_init();
void	CPUTIMER_init();
void	DAC_init();
void	EPWM_init();
void	GPIO_init();
void	INPUTXBAR_init();
void	INTERRUPT_init();
void	SCI_init();
void	SYNC_init();
void	XINT_init();
void	PinMux_init();

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

#endif  // end of BOARD_H definition
